<?php  

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class user_worksheet extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		
		// check if user logged in 
		if (!$this->ion_auth->logged_in())
	  	{
			redirect('auth/login');
	  	}		
		$this->load->library('form_validation');
		//$this->load->model('settings/bank_model');
		 	$this->load->library('datatables');		
	}
		
	
	function create_worksheet()
	{
		$this->data['page_title'] = "Create Worksheet";
		$meta['page_title'] = "Create Worksheet";
		
	//	$this->data['groups']=$this->accgroup_model->get_group();
		/*if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
		{
			redirect('auth', 'refresh');
		}for checking the authentication*/

		//validate form input
		$this->form_validation->set_rules('date', 'Date', 'required');
		$this->form_validation->set_rules('customer_name', 'Customer_name', 'required');
		$this->form_validation->set_rules('dept', 'Name/Department/Designation', 'required');
		$this->form_validation->set_rules('payment_follow', 'payment Follow Up', 'required');
		$this->form_validation->set_rules('enq_discuss', 'Enquiry discussed', 'required');
		$this->form_validation->set_rules('order_discuss', 'Order discussed', 'required');
		$this->form_validation->set_rules('trip_exp', 'Trip Expenses', 'required');
		$this->form_validation->set_rules('suggestion', 'Suggestion for the Next trip', 'required');
		if ($this->form_validation->run() == true)
		{
			echo $this->session->id;
			exit;
			$data = array(
				'date' => $this->input->post('date'),
				'customer_name' => $this->input->post('date'),
				'dept' => $this->input->post('dept'),
				'payment_follow' => $this->input->post('payment_follow'),
				'enq_discuss' => $this->input->post('enq_discuss'),
				'order_discuss' => $this->input->post('order_discuss'),
				'trip_exp' => $this->input->post('trip_exp'),
				'suggestion'  => $this->input->post('suggestion'),
			);
		print_r($data);exit;
			
		}
		if ($this->form_validation->run() == true) 
		{
			//$this->bank_model->insert_bank($data);
			//redirect("settings/bank/get_all_bank");
			//check to see if we are creating the user
			//redirect them back to the admin page
			//$this->session->set_flashdata('message', $this->ion_auth->messages());
			//redirect("auth", 'refresh');
		}
		else
		{
			//display the create user form
			//set the flash data error message if there is one
			$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

			$this->data['date'] = array(
				'name'  => 'date',
				'id'    => 'date',
				'type'  => 'text',
				'value' => $this->form_validation->set_value('date'),
			);
			$this->data['customer_name'] = array(
				'name'  => 'customer_name',
				'id'    => 'customer_name',
				'type'  => 'text',
				'value' => $this->form_validation->set_value('customer_name'),
			);
				$this->data['dept'] = array(
				'name'  => 'dept',
				'id'    => 'dept',
				'type'  => 'text',
				'value' => $this->form_validation->set_value('dept'),
			);
	
			$this->data['enq_discuss'] = array(
				'name'  => 'enq_discuss',
				'id'    => 'enq_discuss',
				'type'  => 'textarea',
				'value' => $this->form_validation->set_value('enq_discuss'),
			);
	
			$this->data['order_discuss'] = array(
				'name'  => 'order_discuss',
				'id'    => 'order_discuss',
				'type'  => 'textarea',
				'value' => $this->form_validation->set_value('order_discuss'),
			);
			
			$this->data['date'] = array(
				'name'  => 'date',
				'id'    => 'date',
				'type'  => 'text',
				'class' => 'datepicker',
				'value' => $this->form_validation->set_value('date'),
			);
			
			$this->data['payment_follow'] = array(
				'name'  => 'payment_follow',
				'id'    => 'payment_follow',
				'type'  => 'text',
				'value' => $this->form_validation->set_value('payment_follow'),
			);
				$this->data['trip_exp'] = array(
				'name'  => 'trip_exp',
				'id'    => 'trip_exp',
				'type'  => 'text',
				'value' => $this->form_validation->set_value('trip_exp'),
			);
			$this->data['suggestion'] = array(
				'name'  => 'suggestion',
				'id'    => 'suggestion',
				'type'  => 'text',
				'value' => $this->form_validation->set_value('suggestion'),
			);
			
		//	print_r($this->data);exit;

			$this->load->view('common/header',$meta);
			$this->load->view('hrm/user/worksheet', $this->data);
			$this->load->view('common/footer');
		}
	}
	
	function get_all_bank(){
		//list the users
		
	//$this->data['users'] = $this->bank_model->get_bank()->result();
			
//			print_r($this->data['users']);exit; 
	// $this->data['user_type'] =  $this->ion_auth_model->get_user_type($this->session->userdata('user_id'))->row();
	  //echo $get_user_type->name;
	   
	  // exit;
	   $meta['page_title'] = "Bank List";
	   $this->data['message'] = "Bank Added Successfully";
	 //  $this->session->set_flashdata('message', 'User Created Successfully');
	   $this->load->view('common/header', $meta);
	   $this->load->view('settings/bank/view_bank1',$this->data);
       $this->load->view('common/footer');
	   
		}
	

	function edit_bank($id)
	{
		
		$this->data['page_title'] = "Edit Bank";
		$meta['page_title'] = "Edit Bank";
		//$this->data['groups']=$this->bank_model->get_tax();
		if (!$this->ion_auth->logged_in())
		{
			redirect('auth', 'refresh');
		}

		$user = $this->bank_model->edit_bank($id)->row();
		//print_r($user);exit;
		//$groups=$this->ion_auth->groups()->result_array();
		//$currentGroups = $this->ion_auth->get_users_groups($id)->result();
		
		//getting the user type ex. team lead 
		//$get_user_type = $this->ion_auth_model->user_type()->result_array();
		 //$currentUser = $this->ion_auth_model->get_user_type($id)->result();
		
		//getting the user type ex. fedonic 
		//$get_departments = $this->ion_auth_model->departments()->result_array();
		 //$currentDepartments = $this->ion_auth_model->get_user_department($id)->result();
		
		//process the phone number
		//if (isset($user->phone) && !empty($user->phone))
	//	{
			//$user->phone = explode('-', $user->phone);
		//}

		//validate form input
		$this->form_validation->set_rules('name', 'Bank Name', 'required|xss_clean');
		$this->form_validation->set_rules('address', 'Bank Address', 'required|xss_clean');
		/*$this->form_validation->set_rules('phone2', 'Second Part of Phone', 'required|xss_clean|min_length[3]|max_length[3]');
		$this->form_validation->set_rules('phone3', 'Third Part of Phone', 'required|xss_clean|min_length[4]|max_length[4]');
		$this->form_validation->set_rules('company', 'Company Name', 'required|xss_clean');*/
		
		//$this->form_validation->set_rules('groups', 'Groups', 'xss_clean');

		if (isset($_POST) && !empty($_POST))
		{
			// do we have a valid request?
			/*if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
			{
				show_error('This form post did not pass our security checks.');
			}*/

			$data = array(
				'name' => $this->input->post('name'),
				'address'  => $this->input->post('address')
			);
			//print_r($data);
			//print_r($user->id);exit;
			//Update the groups user belongs to
			if ($this->form_validation->run() === TRUE)
			{
				$this->bank_model->update($user->id, $data);
				redirect("settings/bank/get_all_bank");
				//check to see if we are creating the user
				//redirect them back to the admin page
			}
		}

		//display the edit user form
		//$this->data['csrf'] = $this->_get_csrf_nonce();

		//set the flash data error message if there is one
		$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

		//pass the user to the view
		$this->data['user'] = $user;
		//$this->data['groups'] = $groups;
		//$this->data['currentGroups'] = $currentGroups;
		
		//user type 
		
		//$this->data['user_type'] = $get_user_type;
	//	$this->data['currentUser'] = $currentUser;
		
		//user departments
		
		//$this->data['get_departments'] = $get_departments;
		//$this->data['currentDepartments'] = $currentDepartments;		
		

		$this->data['name'] = array(
			'name'  => 'name',
			'id'    => 'name',
			'type'  => 'text',
			'value' => $this->form_validation->set_value('name', $user->name),
		);
		$this->data['address'] = array(
			'name'  => 'address',
			'id'    => 'address',
			'type'  => 'text',
			'value' => $this->form_validation->set_value('amount', $user->address),
		);
		/*$this->data['phone2'] = array(
			'name'  => 'phone2',
			'id'    => 'phone2',
			'type'  => 'text',
			'class' => 'span2',
			'value' => $this->form_validation->set_value('phone2', $user->phone[1]),
		);
		$this->data['phone3'] = array(
			'name'  => 'phone3',
			'id'    => 'phone3',
			'type'  => 'text',
			'class' => 'span2',
			'value' => $this->form_validation->set_value('phone3', $user->phone[2]),
		);*/
		
		$this->data['submit'] = array(
			'name' => 'submit',
			'id'   => 'submit',
			'type' => 'submit',
			'value' =>'Save Edit',
			'class' =>'btn btn-success'
		);
		
		//print_r($this->data);exit;
		$meta['page_title'] = "Edit Bank";
		 $this->load->view('common/header',$meta);
		$this->load->view('settings/bank/edit_bank', $this->data, $id);
		 $this->load->view('common/footer');
	}

	

	function delete_tax($id){
		$this->bank_model->delete($id);
		redirect("settings/bank/get_all_bank");		
	}
	
	function get(){
		echo $this->bank_model->get();
	}


}
?>